<template>
  <div class="wrap">
    <div class="order">积分订单</div>

    <div class="content">

      <table v-for="(item,index) in orders" v-if="item.isjifen===1">
        <tr>
          <th>订单号：{{item.order_number}}</th>
          <th>下单日期：{{item.order_time}}</th>
          <th></th>
          <th></th>
          <th class="status">订单状态：<span>{{item.order_status}}</span></th>
        </tr>
        <tr>
          <td><img class="img" :src="item.product_img" alt="">{{item.product_name}}</td>
          <td class="size">{{item.size}}</td>
          <td class="price">×{{item.goods_num}}</td>
          <td class="total">积分：{{item.jifen}}</td>
          <td class="operation">
            <p @click="jifenDetail()">查看详情</p>
            <button @click="del(index)" v-if="item.order_status==='已完成'">删除订单</button>
          </td>
        </tr>
      </table>

    </div>

  </div>
</template>

<script>
  import Axios from 'axios'
  export default {
    name: "PointsOrders",
    data() {
      return {
        orders: []
      }
    },
    methods: {
      del(ind) {
        console.log(ind);
        var id = this.orders[ind].orderitem_id;
        console.log(id);
        var con = confirm('确定要删除吗？');
        if (con == true) {
          var params = new URLSearchParams();
          params.append('orderitem', id);
          Axios.post('/api/order/point', params).then(res => {

          });
          location.reload();
        } else {
          return
        }
      },
      jifenDetail() {
        this.$router.push({path: '/mine/jifen'});
      }
    },
    mounted() {
      var params = new URLSearchParams();
      params.append('user_id', 1);
      Axios.post('/api/order/find', params).then(res => {
        this.orders = res.data;
        console.log(this.orders);
      });
    }
  }
</script>

<style scoped>
  .wrap {
    box-sizing: border-box;
    width: 100%;
    min-height: 626px;
    border: 1px solid #e9e9e9;
  }
  .order {
    box-sizing: border-box;
    width: 100%;
    height: 58px;
    padding-left: 20px;
    font-size: 18px;
    line-height: 58px;
    border-bottom: 1px solid #e9e9e9;
  }

  .content {
    padding: 20px;
  }

  .img {
    box-sizing: border-box;
    width: 80px;
    height: 80px;
    margin: 20px;
    vertical-align: middle;
    border: 1px solid #e9e9e9;
  }
  table {
    width: 100%;
    border: 1px solid #e9e9e9;
    border-bottom: none;
    margin-bottom: 20px;
  }
  tr {
    width: 100%;
  }
  th {
    height: 46px;
    background: #f2f2f2;
    font-size: 16px;
  }
  th p {
    color: #4b943d;
  }
  th span {
    color: #f08200;
  }
  td {
    font-size: 14px;
    border-bottom: 1px solid #e9e9e9;
  }

  .status {
    width: 150px;
  }
  .size {
    text-align: center;
    color: #999;
  }
  .price {
    width: 150px;
  }
  .total {
    width: 180px;
    text-align: center;
    border-left: 1px solid #e9e9e9;
    border-right: 1px solid #e9e9e9;
  }
  .operation {
    text-align: center;
  }
  .operation p {
    color: #4b943d;
    text-decoration: underline;
    margin-bottom: 20px;
    cursor: pointer;
  }
  .operation button {
    width: 90px;
    height: 30px;
    background: #f08200;
    color: #fff;
    line-height: 30px;
    border-radius: 5px;
    display: block;
    margin: 0 auto;
    margin-bottom: 20px;
    cursor: pointer;
  }


</style>
